package paper.crawler;

import java.io.File;
import paper.http.ClassReLoader;

public class HillManager {
    ClassLoader localClassLoader = null;
    long lastModifiedTime = 0;
    File classFiles = new File("dist/lib/paperBase.jar");
    Class hillClass;

    final String className = "paper.crawler.BlindHTMLParser";

    public synchronized HillClimber makeHillClimber(String className) {
        try {
            long t = classFiles.lastModified();
            if (t > lastModifiedTime) {
                lastModifiedTime = t;
                localClassLoader = null;
                hillClass = null;
                System.gc();
                System.gc();
            }
            if (localClassLoader == null) {
                localClassLoader = new ClassReLoader();
                hillClass = Class.forName(className,true,localClassLoader);
            }
            return (HillClimber) hillClass.getConstructor().newInstance();
        } catch (Exception e) {
            System.err.println("Failed to create HillClimber " + e);
        }
        return null;
    }

}
